package com.heima.kafka.listener;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojos.User;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;


/**
 * 消息消费者
 * */
@Component
public class HelloListener {

    /**
     * 传递消息为字符串
     * */
    @KafkaListener(topics = "itcast-topic")
    public void onMessage(String message){
        if(!StringUtils.isEmpty(message)){
            System.out.println(message);
        }
    }

    /**
     * 传递消息为对象
     * */
    @KafkaListener(topics = "user-topic")
    public void onObject(String message){
        if(!StringUtils.isEmpty(message)){
            User user = JSON.parseObject(message,User.class);
            System.out.println(user);
        }
    }


}
